package com.yl.demo;

import com.yl.demo.base.config.AuthProperties;
import com.yl.demo.base.config.SharedConfigurationReference;
import com.yl.demo.web.HelloController;
import org.mybatis.spring.annotation.MapperScan;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.web.servlet.ServletComponentScan;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Import;
import org.springframework.core.env.Environment;

import java.net.InetAddress;
import java.net.UnknownHostException;

@SpringBootApplication
//druid 数据连接池监控日志
@ServletComponentScan
//自定义属性 properties
@EnableConfigurationProperties({AuthProperties.class})
//将项目中对应的mapper类的路径加进来就可以了
//开启缓存策略
@EnableCaching
//配置扫码第三方jar包
@Import(SharedConfigurationReference.class)
@MapperScan("com.yl.demo.mapper")
public class SpringMyabtisShiroApplication extends SpringBootServletInitializer {

    private final static Logger logger = LoggerFactory.getLogger(HelloController.class);

    /**
     * 参数里VM参数设置为：
     * <p>
     * -javaagent:.\lib\springloaded-1.2.4.RELEASE.jar -noverify
     *
     * @param args
     */
    public static void main(String[] args)  throws UnknownHostException {
        ConfigurableApplicationContext application = SpringApplication.run(SpringMyabtisShiroApplication.class, args);
        Environment env = application.getEnvironment();
        String ip = InetAddress.getLocalHost().getHostAddress();
        String port = env.getProperty("server.port");
        String path = env.getProperty("server.servlet.context-path");
        logger.info("\n----------------------------------------------------------\n\t" +
                "Application Spring-Myabtis-Shiro is running! Access URLs:\n\t" +
                "Local: \t\thttp://localhost:" + port + path + "/\n\t" +
                "External: \thttp://" + ip + ":" + port + path + "/\n\t" +
                "----------------------------------------------------------");
    }
}
